package com.one.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.one.bean.User;
import com.one.bean.UserLogin;
import com.one.mapper.UserLoginMapper;
import com.one.mapper.UserMapper;
import com.one.service.WechatAuthService;
import com.one.vo.UserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author ShiWen
 * @date 2022/1/17 9:40
 * @Version 1.0
 * @Description TODO
 */
@Service
public class WechatAuthServiceImpl implements WechatAuthService {
    @Autowired
    private UserLoginMapper userLoginMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserVo findWechatByOpenId(String openid) {
        LambdaQueryWrapper<UserLogin> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserLogin::getOpenid,openid);
        // 查询到登录信息
        UserLogin userLogin = userLoginMapper.selectOne(wrapper);
        if (userLogin==null){
            return null;
        }
        User user = userMapper.selectById(userLogin.getUserId());
        // 详细信息
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(userLogin,userVo);
        BeanUtils.copyProperties(user,userVo);
        return userVo;
    }
}
